﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using schedulelist.ORM.dao.interfaces;
using schedulelist.ORM.domain;
using NHibernate;
namespace schedulelist.ORM.dao.classes
{
    class CategoryDAO : GenericDAO<Category>, ICategoryDAO
    {
        public CategoryDAO(ISession session) : base(session) { }

        public Category getCategoryByName(
        string name)
        {
            var list = session.CreateSQLQuery(
            "SELECT category.* FROM category" +
            " WHERE category.name='" + name + "'")
            .AddEntity("Category", typeof(Category))
            .List<Category>();
            Category cat = list[0];
            return cat;
        }

        public Category getCategoryById(
        int id)
        {
            var list = session.CreateSQLQuery(
            "SELECT category.* FROM category" +
            " WHERE category.Id='" + id + "'")
            .AddEntity("Category", typeof(Category))
            .List<Category>();
            Category cat = list[0];
            return cat;
        }
    }
}
